<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Searches the language tag list for the best match to the language</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="locale.getscript.html">Locale::getScript</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="locale.parselocale.html">Locale::parseLocale</a></div>
 <div class="up"><a href="class.locale.html">Locale</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="locale.lookup" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Locale::lookup</h1>
  <h1 class="refname">locale_lookup</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Locale::lookup</span> -- <span class="refname">locale_lookup</span> &mdash; <span class="dc-title">Searches the language tag list for the best match to the language</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-locale.lookup-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="modifier">static</span>
   <span class="type">string</span> 
   <span class="methodname"><strong>Locale::lookup</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$langtag</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$canonicalize</code><span class="initializer"> = false</span></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$default</code></span>
  ]] )</div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> 
   <span class="methodname"><strong>locale_lookup</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$langtag</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$locale</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$canonicalize</code><span class="initializer"> = false</span></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$default</code></span>
  ]] )</div>

  <p class="para rdfs-comment">
   Searches the items in <em><code class="parameter">langtag</code></em> for the best match to 
   the language range specified in <em><code class="parameter">locale</code></em> according to
   RFC 4647&#039;s lookup algorithm. 
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-locale.lookup-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">langtag</code></em></dt>

     <dd>

      <p class="para">
       An <span class="type"><a href="language.types.array.html" class="type array">array</a></span> containing a list of language tags to compare to 
       <em><code class="parameter">locale</code></em>. Maximum 100 items allowed.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">locale</code></em></dt>

     <dd>

      <p class="para">
       The locale to use as the language range when matching.
      </p>
     </dd>

    
     
       <dt>

         <em><code class="parameter">canonicalize</code></em>
       </dt>

       <dd>

         <p class="para">
           If true, the arguments will be converted to canonical form before
           matching.
         </p>
       </dd>

     
     
     <dt>
<em><code class="parameter">default</code></em></dt>

     <dd>

      <p class="para">
       The locale to use if no match is found.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>



 <div class="refsect1 returnvalues" id="refsect1-locale.lookup-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The closest matching language tag or default value.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-locale.lookup-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2496">
   <p><strong>Example #1 <span class="function"><strong>locale_lookup()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$arr&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-DEVA'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-DE-1996'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-De'<br /></span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">locale_lookup</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'de-DE-1996-x-prv1-prv2'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-2497">
   <p><strong>Example #2 OO example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$arr&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-DEVA'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-DE-1996'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'de-De'<br /></span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">Locale</span><span style="color: #007700">::</span><span style="color: #0000BB">lookup</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'de-DE-1996-x-prv1-prv2'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <p class="para">以上例程会输出：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
de_de_1996
</pre></div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-locale.lookup-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="locale.filtermatches.html" class="function" rel="rdfs-seeAlso">locale_filter_matches()</a> - Checks if a language tag filter matches with locale</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="locale.getscript.html">Locale::getScript</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="locale.parselocale.html">Locale::parseLocale</a></div>
 <div class="up"><a href="class.locale.html">Locale</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
